﻿using System;
using System.Diagnostics;

namespace Bing
{
    /// <summary>
    /// Contains parameters for a request to the Video SourceType.
    /// </summary>
    [DebuggerDisplay("Filters: {Filters.ToString(), SortBy: {SortBy}")]
    public class VideoRequest: IBingRequest
    {

        /// <summary>
        /// Gets or sets specifies the number of results to return per <see cref="VideoRequest"/>.
        /// </summary>
        /// <value>Specifies the number of results to return per <see cref="VideoRequest"/>.</value>
        /// <remarks>
        /// If the number of results per page requested in the <see cref="VideoRequest"/>.Count field is greater than the total number of results returned in the <see cref="VideoResponse"/>.Total field, the number of results per page will be equal to the total number of results.<br />
        /// The default value for Count is 10 (ten), and the maximum count value is 50. If a value greater than 50 is specified, the Bing API returns an error.<br />
        /// Search results are limited to the first 1,000 results. This means that the total of <see cref="VideoRequest"/>.Count plus <see cref="VideoRequest"/>.Offset should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Count { get; set; }

        /// <summary>
        /// Gets or sets the specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="VideoRequest"/>.
        /// </summary>
        /// <value>Specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="VideoRequest"/>.</value>
        /// <remarks>
        /// The offset specifies the requested position in the result set for the response that is returned for this source. <br />
        /// <b>Offset</b> is typically used in conjunction with the <b>Count</b> property on the <b>SourceRequest</b> object, and the <b>Total</b> property on the <see cref="VideoResponse"/> object, to facilitate paging through long lists of results.<br />
        /// The default value for <b>>Offset</b> is 0 (zero), and the maximum offset value is 1,000. If any other value is specified, an error is returned.<br />
        /// Search results are limited to the first 1,000 results. This means that the total of <b><see cref="VideoRequest"/>.Count</b> plus <b><see cref="VideoRequest"/>.Offset</b> should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Offset { get; set; }

        /// <summary>
        /// Gets or sets the array of strings that filter the response the API sends based on size, aspect, color, style, face, or any combination thereof.
        /// </summary>
        /// <value>Array of strings that filter the response the API sends based on size, aspect, color, style, face, or any combination thereof.</value>
        /// <remarks>
        /// Values that can be included in this array are: <br />
        /// <table>
        /// <tr><td><b>Value</b></td><td><b>Restricts results to videos:</b></td>td></tr>
        /// <tr><td>Duration:Short</td><td>The runtime of which is less than 300 seconds</td></tr>
        /// <tr><td>Duration:Medium</td><td>The runtime of which is between 300 seconds and 12000 seconds</td></tr>
        /// <tr><td>Duration:Long</td><td>The runtime of which is greater than 12000 seconds</td></tr>
        /// <tr><td>Aspect:Standard</td><td>That have standard aspect ratio</td></tr>
        /// <tr><td>Aspect:Widescreen</td><td>That have widescreen aspect ratio</td></tr>
        /// <tr><td>Resolution:Low</td><td>That have low resolution</td></tr>
        /// <tr><td>Resolution:Medium</td><td>That have medium resolution</td></tr>
        /// <tr><td>Resolution:High</td><td>That have high resolution</td></tr>
        /// </table>
        /// <b>Important</b><br/>
        /// You cannot include more than one value for duration in the same request.
        /// </remarks>
        public string[] Filters { get; set; }

        /// <summary>
        /// Gets or sets the sort order of results returned from the Video <see cref="ApiHelper.SourceType"/>.
        /// </summary>
        /// <value>Specifies the sort order of results returned from the Video <see cref="ApiHelper.SourceType"/>.</value>
        public ApiHelper.VideoSortOption SortBy { get; set; }


        /// <summary>
        /// Creates the query string for the API call.
        /// </summary>
        /// <returns>The query string to append to the call.</returns>
        public string ToQueryString()
        {
            string request = string.Format("&Video.Count={0}", Count);
            request += string.Format("&Video.Offset={0}", Offset);
            foreach (string s in Filters)
            {
                request += string.Format("&Video.Filters={0}", s);    
            }
            return request;
        }
    }
}
